//方块
function Block(parent, option) {
    option = option || {};
    //设置方块属性
    this.width = option.width || 20;
    this.height = option.height || 20;
    this.backgroundColor = option.backgroundColor || 'red';
    this.x = option.x || 0;
    this.y = option.y || 0;

    this.parent = parent;
}

//渲染方块到页面上
Block.prototype.render = function() {
    this.elem = document.createElement('div');
    this.parent.appendChild(this.elem);
    //设置样式
    this.elem.style.width = this.width + 'px';
    this.elem.style.height = this.height + 'px';
    this.elem.style.backgroundColor = this.backgroundColor;
    this.elem.style.left = this.x + 'px';
    this.elem.style.top = this.y + 'px';
}

//随即更改位置
Block.prototype.positionRandom = function() {
    this.x = Tools.getRandom(0, this.parent.clientWidth / this.width - 1) * this.width;
    this.y = Tools.getRandom(0, this.parent.clientHeight / this.height - 1) * this.height;

    this.elem.style.left = this.x + 'px';
    this.elem.style.top = this.y + 'px';
}